package lkj.dao.admin.impl;

import lkj.dao.admin.AdminDao;
import lkj.domain.admin.Admin;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * Created by lkj10 on 2017/3/12.
 */
@Repository
public class ActionDaoImpl implements AdminDao {
    @Resource
    private SessionFactory sessionFactory;

    protected Session getSession(){
        Session session=sessionFactory.getCurrentSession();
        return session;
    }
    @Override
    public Admin findByUser(String username, String password) {
        Admin admin= (Admin) getSession().createQuery(
                "from Admin u where u.username=? and u.password=?")
                .setParameter(0,username)
                .setParameter(1,password)
                .uniqueResult();
        return admin;
    }
}
